#include "stdafx.h"
#include "ConfigOperatorMap.h"

namespace woe
{
	ConfigOperatorMap::ConfigOperatorMap()
	{

	}

	ConfigOperatorMap::~ConfigOperatorMap()
	{
		m_configData.clear();
	}

	bool ConfigOperatorMap::Get(const std::string& key, int& nVal) const
	{
		if ( m_configData.empty() )
		{
			return false;
		}
		ConfigDataMapIter it = m_configData.find( key );
		if ( it == m_configData.end() )
		{
			return false;
		}
		nVal = atoi(it->second.c_str());
		return true;
	}

	bool ConfigOperatorMap::Get(const std::string& key, float& fVal) const
	{
		if ( m_configData.empty() )
		{
			return false;
		}
		ConfigDataMapIter it = m_configData.find( key );
		if ( it == m_configData.end() )
		{
			return false;
		}
		fVal = atof(it->second.c_str());
		return true;
	}

	bool ConfigOperatorMap::Get(const std::string& key, std::string& strVal) const
	{
		if ( m_configData.empty() )
		{
			return false;
		}
		ConfigDataMapIter it = m_configData.find( key );
		if ( it == m_configData.end() )
		{
			return false;
		}
		strVal = it->second;
		return true;
	}

	bool ConfigOperatorMap::Set(const std::string &key, const int &nVal)
	{
		char tmp[25] = "";
		sprintf(tmp,"%d",nVal);
		m_configData[key] =  tmp ;
		return true;
	}

	bool ConfigOperatorMap::Set(const std::string &key, const float &fVal)
	{
		char tmp[25] = "";
		sprintf(tmp,"%f",fVal);
		m_configData[key] =  tmp ;
		return true;
	}

	bool ConfigOperatorMap::Set(const std::string &key, const std::string &strVal)
	{
		m_configData[key] = strVal;
		return true;
	}

	bool ConfigOperatorMap::GetNext(std::string& key, std::string& value)
	{
		static ConfigDataMapIter it = m_configData.begin();
		if ( it == m_configData.end() )
		{
			return false;
		}
		key = (*it).first;
		value = (*it).second;
		++it;
		return true;
	}
}
